Skip to content

fix: defer icon source resolution until component completion#3154

Merged
18202781743 merged 1 commit intolinuxdeepin:dcc-coredumpfrom
18202781743:flow
Apr 3, 2026
Merged

fix: defer icon source resolution until component completion#3154
18202781743 merged 1 commit intolinuxdeepin:dcc-coredumpfrom
18202781743:flow

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 commented Apr 3, 2026

  1. Added QQmlParserStatus interface to DccObject to track QML component lifecycle
  2. Introduced m_componentComplete flag to track when component construction is finished
  3. Modified setIcon() to delay icon source resolution until componentComplete() is called
  4. Added updateIconSource() private method to handle icon URL resolution logic
  5. Added componentComplete() override to set completion flag and trigger icon source update
  6. Added classBegin() override as required by QQmlParserStatus interface
  7. Made DccObject inherit from QQmlParserStatus and added Q_INTERFACES macro
  8. Added friend declaration for DccModel class to access private members

This fix addresses an issue where icon source resolution was attempted during QML component construction phase when the QQmlContext might not be fully initialized. By deferring the URL resolution until componentComplete(), we ensure the context is properly set up, preventing potential crashes or incorrect icon paths.

Log: Fixed icon loading issues during control center module initialization

Influence:

  1. Test icon loading for all control center modules
  2. Verify icons appear correctly after QML component initialization
  3. Test dynamic icon changes after component completion
  4. Verify no crashes during control center startup
  5. Test icon resolution with both relative and absolute paths
  6. Verify icon updates when setIcon() is called after component completion

fix: 延迟图标源解析直到组件完成

  1. 为 DccObject 添加 QQmlParserStatus 接口以跟踪 QML 组件生命周期
  2. 引入 m_componentComplete 标志来跟踪组件构造何时完成
  3. 修改 setIcon() 方法,将图标源解析延迟到 componentComplete() 被调用时
  4. 添加 updateIconSource() 私有方法来处理图标 URL 解析逻辑
  5. 添加 componentComplete() 重写以设置完成标志并触发图标源更新
  6. 添加 classBegin() 重写以满足 QQmlParserStatus 接口要求
  7. 使 DccObject 继承自 QQmlParserStatus 并添加 Q_INTERFACES 宏
  8. 为 DccModel 类添加友元声明以访问私有成员

此修复解决了在 QML 组件构造阶段尝试解析图标源时 QQmlContext 可能未完全初
始化的问题。通过将 URL 解析延迟到 componentComplete(),我们确保上下文已
正确设置,防止潜在的崩溃或错误的图标路径。

Log: 修复控制中心模块初始化期间的图标加载问题

Influence:

  1. 测试所有控制中心模块的图标加载
  2. 验证 QML 组件初始化后图标是否正确显示
  3. 测试组件完成后的动态图标更改
  4. 验证控制中心启动期间无崩溃
  5. 测试相对路径和绝对路径的图标解析
  6. 验证组件完成后调用 setIcon() 时的图标更新

Summary by Sourcery

Defer QML icon URL resolution in DccObject until the component construction is complete to avoid using an uninitialized QQmlContext.

Bug Fixes:

  • Prevent icon source resolution during QML component construction by delaying it until componentComplete() is called.

Enhancements:

  • Introduce QQmlParserStatus lifecycle handling in DccObject to track component completion and centralize icon source update logic.

1. Added QQmlParserStatus interface to DccObject to track QML component
lifecycle
2. Introduced m_componentComplete flag to track when component
construction is finished
3. Modified setIcon() to delay icon source resolution until
componentComplete() is called
4. Added updateIconSource() private method to handle icon URL resolution
logic
5. Added componentComplete() override to set completion flag and trigger
icon source update
6. Added classBegin() override as required by QQmlParserStatus interface
7. Made DccObject inherit from QQmlParserStatus and added Q_INTERFACES
macro
8. Added friend declaration for DccModel class to access private members

This fix addresses an issue where icon source resolution was attempted
during QML component construction phase when the QQmlContext might
not be fully initialized. By deferring the URL resolution until
componentComplete(), we ensure the context is properly set up,
preventing potential crashes or incorrect icon paths.

Log: Fixed icon loading issues during control center module
initialization

Influence:
1. Test icon loading for all control center modules
2. Verify icons appear correctly after QML component initialization
3. Test dynamic icon changes after component completion
4. Verify no crashes during control center startup
5. Test icon resolution with both relative and absolute paths
6. Verify icon updates when setIcon() is called after component
completion

fix: 延迟图标源解析直到组件完成

1. 为 DccObject 添加 QQmlParserStatus 接口以跟踪 QML 组件生命周期
2. 引入 m_componentComplete 标志来跟踪组件构造何时完成
3. 修改 setIcon() 方法,将图标源解析延迟到 componentComplete() 被调用时
4. 添加 updateIconSource() 私有方法来处理图标 URL 解析逻辑
5. 添加 componentComplete() 重写以设置完成标志并触发图标源更新
6. 添加 classBegin() 重写以满足 QQmlParserStatus 接口要求
7. 使 DccObject 继承自 QQmlParserStatus 并添加 Q_INTERFACES 宏
8. 为 DccModel 类添加友元声明以访问私有成员

此修复解决了在 QML 组件构造阶段尝试解析图标源时 QQmlContext 可能未完全初
始化的问题。通过将 URL 解析延迟到 componentComplete(),我们确保上下文已
正确设置,防止潜在的崩溃或错误的图标路径。

Log: 修复控制中心模块初始化期间的图标加载问题

Influence:
1. 测试所有控制中心模块的图标加载
2. 验证 QML 组件初始化后图标是否正确显示
3. 测试组件完成后的动态图标更改
4. 验证控制中心启动期间无崩溃
5. 测试相对路径和绝对路径的图标解析
6. 验证组件完成后调用 setIcon() 时的图标更新
@18202781743 18202781743 requested a review from caixr23 April 3, 2026 07:01
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 3, 2026

Reviewer's Guide

Defers DccObject icon URL resolution until the QML component lifecycle has completed by implementing QQmlParserStatus, tracking component completion, and centralizing icon source updates in a new helper method.

Sequence diagram for deferred icon URL resolution in DccObject

sequenceDiagram
  participant QmlEngine
  participant QQmlContext
  participant DccObject
  participant DccObject_Private as DccObject_Private

  QmlEngine->>DccObject: construct
  QmlEngine->>DccObject: classBegin()
  activate DccObject

  QmlEngine->>DccObject: setIcon(icon)
  DccObject->>DccObject_Private: store icon in m_icon
  DccObject->>DccObject: emit iconChanged
  DccObject->>DccObject_Private: check m_componentComplete (false)
  DccObject-->DccObject: skip updateIconSource()

  QmlEngine->>DccObject: componentComplete()
  DccObject->>DccObject_Private: m_componentComplete = true
  DccObject->>DccObject: updateIconSource()
  DccObject->>QQmlContext: qmlContext(this)
  QQmlContext-->>DccObject: context
  DccObject->>QQmlContext: resolvedUrl(m_icon)
  QQmlContext-->>DccObject: resolvedUrl
  DccObject->>DccObject_Private: store resolvedUrl in m_iconSource
  DccObject->>DccObject: emit iconSourceChanged
  deactivate DccObject

  QmlEngine->>DccObject: setIcon(newIcon) after completion
  DccObject->>DccObject_Private: update m_icon
  DccObject->>DccObject: emit iconChanged
  DccObject->>DccObject: updateIconSource()
  DccObject->>QQmlContext: qmlContext(this)
  QQmlContext-->>DccObject: context
  DccObject->>QQmlContext: resolvedUrl(m_icon)
  QQmlContext-->>DccObject: resolvedUrl
  DccObject->>DccObject_Private: update m_iconSource
  DccObject->>DccObject: emit iconSourceChanged
Loading

Class diagram for updated DccObject lifecycle and icon handling

classDiagram

class QQmlParserStatus {
  <<interface>>
  +classBegin() void
  +componentComplete() void
}

class DccModel

class DccObject {
  <<QObject>>
  +setIcon(icon QString) void
  +iconSource() QUrl
  +classBegin() void
  +componentComplete() void
  -updateIconSource() void
  -p_ptr DccObject_Private*
}

class DccObject_Private {
  -m_pageType quint8
  -m_weight quint16
  -m_flags quint32
  -m_componentComplete bool
  -m_icon QString
  -m_iconSource QUrl
  -q_ptr DccObject*
  -m_parent DccObject*
  -m_currentObject DccObject*
}

DccObject ..|> QQmlParserStatus
DccObject *-- DccObject_Private : holds
DccModel .. DccObject : friend
Loading

File-Level Changes

Change Details Files
Defer icon URL resolution until QML component completion and centralize icon source update logic.
  • Changed setIcon() to only emit iconChanged immediately and invoke icon source resolution only after the component is marked complete
  • Introduced private updateIconSource() helper to resolve icon URLs via QQmlContext::resolvedUrl and emit iconSourceChanged
  • Ensured iconSource is updated when componentComplete() is called if an icon is already set
src/dde-control-center/plugin/dccobject.cpp
Make DccObject participate in the QML component lifecycle via QQmlParserStatus and track completion state.
  • Made DccObject inherit QQmlParserStatus and added Q_INTERFACES(QQmlParserStatus)
  • Declared and implemented classBegin() and componentComplete() overrides for QQmlParserStatus
  • Added a m_componentComplete flag in DccObject::Private to track component completion state
src/dde-control-center/plugin/dccobject.h
src/dde-control-center/plugin/dccobject.cpp
src/dde-control-center/plugin/dccobject_p.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dde-control-center/plugin/dccobject.cpp" line_range="337" />
<code_context>
 void DccObject::setIcon(const QString &icon)
</code_context>
<issue_to_address>
**question (bug_risk):** Consider whether delaying iconSource updates until componentComplete is acceptable for C++-only usage.

With the new logic, if setIcon is called before componentComplete, iconSource and iconSourceChanged are deferred. That’s fine for QML, but for objects constructed and used only from C++ (no QQmlEngine / componentComplete), iconSource will never update. If C++‑only usage matters, consider checking `qmlContext(this)` instead of `m_componentComplete`, or treating the "no QQml context" case as implicitly complete so iconSource still gets resolved/propagated.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, caixr23

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@18202781743 18202781743 merged commit 715fa27 into linuxdeepin:dcc-coredump Apr 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants